Skip to content

Fix AOT build failure after search NuGet refactor#3433

Merged
Mpdreamz merged 4 commits into
mainfrom
fix/ci-main
Jun 1, 2026
Merged

Fix AOT build failure after search NuGet refactor#3433
Mpdreamz merged 4 commits into
mainfrom
fix/ci-main

Conversation

@Mpdreamz
Copy link
Copy Markdown
Member

@Mpdreamz Mpdreamz commented Jun 1, 2026

Why

After #3364, main CI fails when publishing the native AOT Elastic.Documentation.Mcp.Remote container. ElasticsearchClientAccessor used DefaultJsonTypeInfoResolver(), which is not compatible with trimming/native AOT (IL2026/IL3050).

What

Restore source-generated JSON serialization for the Elasticsearch client by reintroducing EsJsonContext for Elastic.Internal.Search document types (DocumentationDocument, ParentDocument) and wiring it back into DefaultSourceSerializer, matching the pre-refactor approach without reflection-based resolvers.

Made with Cursor

…actor

PR #3364 introduced DefaultJsonTypeInfoResolver for ES client serialization,
which breaks native AOT publish for Elastic.Documentation.Mcp.Remote. Restore
source-generated EsJsonContext for Elastic.Internal.Search document types.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@Mpdreamz Mpdreamz requested a review from a team as a code owner June 1, 2026 12:27
@Mpdreamz Mpdreamz requested a review from cotti June 1, 2026 12:27
@Mpdreamz Mpdreamz added the bug label Jun 1, 2026
@Mpdreamz Mpdreamz had a problem deploying to integration-tests June 1, 2026 12:27 — with GitHub Actions Failure
@Mpdreamz Mpdreamz enabled auto-merge (squash) June 1, 2026 12:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces AOT-compatible JSON serialization infrastructure for the Elasticsearch client. It adds three new files: a custom JsonConverterFactory and converter for serializing RuleQueryMatchCriteria as { "query_string": ... }, a type info resolver that caches metadata for that type, and an ElasticsearchClientJsonResolver that combines two source-generated JSON contexts with the custom resolver. The client accessor is updated to use this new resolver directly instead of a combined resolver with reflection fallback, and the project is marked as AOT-compatible.

Possibly related PRs

  • elastic/docs-builder#3364: Both PRs modify ElasticsearchClientAccessor's source-serializer and type-info resolver wiring to correctly serialize Elastic.Internal.Search types, with this PR further replacing the prior resolver composition with the new ElasticsearchClientJsonResolver and custom rule-query serialization pieces.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing an AOT build failure caused by the search NuGet refactor, which is the core issue addressed in this PR.
Description check ✅ Passed The description clearly explains the problem (AOT incompatibility with DefaultJsonTypeInfoResolver) and the solution (restoring source-generated JSON serialization), directly related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/ci-main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…ation

Wire Elastic.Internal.Search.SourceGenerationContext together with
docs-builder SourceGenerationContext, and add an AOT-safe converter for the
internal RuleQueryMatchCriteria type used by query rules.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@Mpdreamz Mpdreamz had a problem deploying to integration-tests June 1, 2026 12:43 — with GitHub Actions Failure
Register RuleQueryMatchCriteria converter via JsonConverterFactory during
DefaultSourceSerializer setup only. Do not modify options when lazily
creating JsonTypeInfo after they are frozen.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@Mpdreamz Mpdreamz had a problem deploying to integration-tests June 1, 2026 13:14 — with GitHub Actions Failure
UnsafeAccessor on object resolved get_QueryString on System.Object. Read
QueryString via reflection with trim annotations instead.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@Mpdreamz Mpdreamz temporarily deployed to integration-tests June 1, 2026 13:31 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaTypeInfoResolver.cs (1)

24-30: ⚡ Quick win

Guard against caching JsonTypeInfo across JsonSerializerOptions in RuleQueryMatchCriteriaTypeInfoResolver

  • System.Text.Json requires the returned JsonTypeInfo to match the same JsonSerializerOptions instance passed to GetTypeInfo; returning a JsonTypeInfo created for different options can throw (e.g., InvalidOperationException).
  • In this repo, ElasticsearchClientJsonResolver.Default is only wired into DefaultSourceSerializer from ElasticsearchClientAccessor, which is registered as a singleton, so the current code path is unlikely to exercise multiple JsonSerializerOptions instances. If the resolver is ever reused with multiple clients/options, remove the memoization or cache per JsonSerializerOptions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaTypeInfoResolver.cs`
around lines 24 - 30, The cached field _ruleQueryMatchCriteriaTypeInfo violates
System.Text.Json's requirement that a JsonTypeInfo must be tied to the
JsonSerializerOptions used to create it; update GetTypeInfo so it does not
return a single memoized JsonTypeInfo for different options—either remove the
_ruleQueryMatchCriteriaTypeInfo memoization and always call
CreateRuleQueryMatchCriteriaTypeInfo(options) for the RuleQueryMatchCriteriaType
case, or implement a cache keyed by the JsonSerializerOptions instance (e.g., a
Dictionary<JsonSerializerOptions, JsonTypeInfo>) so
CreateRuleQueryMatchCriteriaTypeInfo is invoked with the correct options; adjust
or remove the _ruleQueryMatchCriteriaTypeInfo field and ensure GetTypeInfo still
compares against RuleQueryMatchCriteriaType.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@src/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaTypeInfoResolver.cs`:
- Around line 24-30: The cached field _ruleQueryMatchCriteriaTypeInfo violates
System.Text.Json's requirement that a JsonTypeInfo must be tied to the
JsonSerializerOptions used to create it; update GetTypeInfo so it does not
return a single memoized JsonTypeInfo for different options—either remove the
_ruleQueryMatchCriteriaTypeInfo memoization and always call
CreateRuleQueryMatchCriteriaTypeInfo(options) for the RuleQueryMatchCriteriaType
case, or implement a cache keyed by the JsonSerializerOptions instance (e.g., a
Dictionary<JsonSerializerOptions, JsonTypeInfo>) so
CreateRuleQueryMatchCriteriaTypeInfo is invoked with the correct options; adjust
or remove the _ruleQueryMatchCriteriaTypeInfo field and ensure GetTypeInfo still
compares against RuleQueryMatchCriteriaType.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6e88c9b5-46a1-4e27-a796-9ffdbda7e6a2

📥 Commits

Reviewing files that changed from the base of the PR and between c51356c and c788806.

📒 Files selected for processing (5)
  • src/services/search/Elastic.Documentation.Search/Common/ElasticsearchClientAccessor.cs
  • src/services/search/Elastic.Documentation.Search/Common/ElasticsearchClientJsonResolver.cs
  • src/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaJsonConverter.cs
  • src/services/search/Elastic.Documentation.Search/Common/RuleQueryMatchCriteriaTypeInfoResolver.cs
  • src/services/search/Elastic.Documentation.Search/Elastic.Documentation.Search.csproj
✅ Files skipped from review due to trivial changes (1)
  • src/services/search/Elastic.Documentation.Search/Elastic.Documentation.Search.csproj

@Mpdreamz Mpdreamz merged commit bc1b00c into main Jun 1, 2026
25 checks passed
@Mpdreamz Mpdreamz deleted the fix/ci-main branch June 1, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants